#include "OtherMSH.h"                                                                                                                   /** MSH on C1 **/

#include <iostream>

using namespace std;

/**
 * delete a product from a category
 * MSH on C1
 **/
void OtherMSH::del (int catID, vector < Category > cats, vector < Product > &prds) {                                                    /** MSH on C1 **/
    bool catGate = false;                                                                                                               /** MSH on C1 **/
    for (vector < Category > ::iterator catIter = cats.begin(); ((catIter != cats.end()) && ! catGate); ++catIter) {                    /** MSH on C1 **/
        if ((*catIter).get_cat_id() == catID) {                                                                                         /** MSH on C1 **/
            cout << "products under this category : " << endl;                                                                          /** MSH on C1 **/
            for (vector < Product > ::iterator prdIter = prds.begin(); prdIter != prds.end(); ++prdIter) {                              /** MSH on C1 **/
                if ((*prdIter).get_cat_id() == catID) {                                                                                 /** MSH on C1 **/
                    cout << (*prdIter).display() << endl;                                                                               /** MSH on C1 **/
                }                                                                                                                       /** MSH on C1 **/
            }                                                                                                                           /** MSH on C1 **/

            int prdID;                                                                                                                  /** MSH on C1 **/
            cout << "product ID to be deleted : "; cin >> prdID;                                                                        /** MSH on C1 **/
            bool prdGate = false;                                                                                                       /** MSH on C1 **/
            for (vector < Product > ::iterator prdIter = prds.begin(); ((prdIter != prds.end()) && ! prdGate); ++prdIter) {             /** MSH on C1 **/
                if ((*prdIter).get_prod_id() == prdID) {                                                                                /** MSH on C1 **/
                    prds.erase(prdIter);                                                                                                /** MSH on C1 **/
                    prdGate = true;                                                                                                     /** MSH on C1 **/
                }                                                                                                                       /** MSH on C1 **/
            }                                                                                                                           /** MSH on C1 **/

            if (prdGate) {                                                                                                              /** MSH on C1 **/
                cout << "selected product deleted" << endl;                                                                             /** MSH on C1 **/
            } else {                                                                                                                    /** MSH on C1 **/
                cout << "no product deleted" << endl;                                                                                   /** MSH on C1 **/
            }                                                                                                                           /** MSH on C1 **/

#ifdef DEBUG                                                                                                                            /** MSH on C1 **/
            cout << "products under this category : " << endl;                                                                          /** MSH on C1 **/
            for (vector < Product > ::iterator prdIter = prds.begin(); prdIter != prds.end(); ++prdIter) {                              /** MSH on C1 **/
                if ((*prdIter).get_cat_id() == catID) {                                                                                 /** MSH on C1 **/
                    cout << (*prdIter).display() << endl;                                                                               /** MSH on C1 **/
                }                                                                                                                       /** MSH on C1 **/
            }                                                                                                                           /** MSH on C1 **/
#endif                                                                                                                                  /** MSH on C1 **/

            catGate = true;                                                                                                             /** MSH on C1 **/
        }                                                                                                                               /** MSH on C1 **/
    }                                                                                                                                   /** MSH on C1 **/
}                                                                                                                                       /** MSH on C1 **/

/**
 * change the price of a given product
 * MSH on C1
 **/
void OtherMSH::edit (int prdID, double prdPrice, vector < Product > &prds) {                                                            /** MSH on C1 **/
    bool prdGate = false;                                                                                                               /** MSH on C1 **/
    for (vector < Product > ::iterator prdIter = prds.begin(); ((prdIter != prds.end()) && ! prdGate); ++prdIter) {                     /** MSH on C1 **/
        if ((*prdIter).get_prod_id() == prdID) {                                                                                        /** MSH on C1 **/

#ifdef DEBUG                                                                                                                            /** MSH on C1 **/
            cout << (*prdIter).get_prd_price() << endl;                                                                                 /** MSH on C1 **/
#endif                                                                                                                                  /** MSH on C1 **/

            (*prdIter).setPrdPrice(prdPrice);                                                                                           /** MSH on C1 **/
            cout << "price changed" << endl;                                                                                            /** MSH on C1 **/

#ifdef DEBUG                                                                                                                            /** MSH on C1 **/
            cout << (*prdIter).get_prd_price() << endl;                                                                                 /** MSH on C1 **/
#endif                                                                                                                                  /** MSH on C1 **/

            prdGate = true;                                                                                                             /** MSH on C1 **/
        }                                                                                                                               /** MSH on C1 **/
    }                                                                                                                                   /** MSH on C1 **/
}                                                                                                                                       /** MSH on C1 **/

/**
 * add a new category
 * MSH on C1
 **/
void OtherMSH::add (int catID, string catName, vector < Category > &cats) {                                                             /** MSH on C1 **/
    bool catExists = false;                                                                                                             /** MSH on C1 **/
    for (vector < Category > ::iterator catIter = cats.begin(); ((catIter != cats.end()) && ! catExists); ++catIter) {                  /** MSH on C1 **/

#ifdef DEBUG                                                                                                                            /** MSH on C1 **/
        cout << (*catIter).display() << endl;                                                                                           /** MSH on C1 **/
#endif                                                                                                                                  /** MSH on C1 **/

        if ((*catIter).get_cat_id() == catID) {                                                                                         /** MSH on C1 **/
            catExists = true;                                                                                                           /** MSH on C1 **/
        }                                                                                                                               /** MSH on C1 **/
    }                                                                                                                                   /** MSH on C1 **/

    if (catExists) {                                                                                                                    /** MSH on C1 **/
        cout << "category with ID = " << catID << " exists already" << endl;                                                            /** MSH on C1 **/
    } else {                                                                                                                            /** MSH on C1 **/
        Category cat = Category(catID, catName);                                                                                        /** MSH on C1 **/
        cats.push_back(cat);                                                                                                            /** MSH on C1 **/
        cout << "category added" << endl;                                                                                               /** MSH on C1 **/
    }                                                                                                                                   /** MSH on C1 **/

#ifdef DEBUG                                                                                                                            /** MSH on C1 **/
    for (vector < Category > ::iterator catIter = cats.begin(); (catIter != cats.end(); ++catIter) {                                    /** MSH on C1 **/
        cout << (*catIter).display() << endl;                                                                                           /** MSH on C1 **/
    }                                                                                                                                   /** MSH on C1 **/
#endif                                                                                                                                  /** MSH on C1 **/

}                                                                                                                                       /** MSH on C1 **/
